﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Gin.Commands
{
    public abstract class CompareStrings: Command
    {
        [GinArgumentText(Multiline = false, MaxLength = 500)]
        public string FirstOperandName { get; set; }

        [GinArgumentText(Multiline = false, MaxLength = 500)]
        public string SecondOperandName { get; set; }

        [GinArgumentText(Multiline = false, MaxLength = 500)]
        public string ResultName { get; set; }

        protected abstract bool Compare(string operand1, string operand2);

        public override void Do(ExecutionContext context)
        {
            string operand1 = (string)(context.GetResult(FirstOperandName));
            string operand2 = (string)(context.GetResult(SecondOperandName));

            bool result = Compare(operand1, operand2);
            context.SaveResult(ResultName, result);
        }
    }

    public class StringStartsWith : CompareStrings
    {
        protected override bool Compare(string operand1, string operand2)
        {
            return operand1.StartsWith(operand2);
        }
    }

    public class StringEndsWith : CompareStrings
    {
        protected override bool Compare(string operand1, string operand2)
        {
            return operand1.EndsWith(operand2);
        }
    }

    public class StringContains : CompareStrings
    {
        protected override bool Compare(string operand1, string operand2)
        {
            return operand1.Contains(operand2);
        }
    }

    public class StringEquals : CompareStrings
    {
        public string ResultName { get; set; }

        protected override bool Compare(string operand1, string operand2)
        {
            return operand1.Equals(operand2);
        }
    }

    public class StringNotEquals : CompareStrings
    {
        protected override bool Compare(string operand1, string operand2)
        {
            return !operand1.Equals(operand2);
        }
    }
}
